package com.example.utils;

import com.example.controller.MessageController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class ScheduledTask {

    private final MessageController messageController;

    @Autowired
    public ScheduledTask(MessageController messageController) {
        this.messageController = messageController;
    }

    @Scheduled(fixedDelay = 5000) // 每隔 5 秒执行一次
    public void pushMessage() {
        System.out.println("执行了");
        messageController.pushMessage("Server push: Hello from the server!");
    }
}
